home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Deutsche Edition 1
/
Deutsche Edition 1.iso
/
amok
/
amok_lha
/
amok03.lha
/
IFFtoCode
/
Sources
/
IFFtoCode.mod
next >
Wrap
Text File
|
1993-08-15
|
9KB
|
312 lines
(*---------------------------------------------------------------------------
:Program. IFFtoCode.mod
:Author. Pit Burkhardt
:Address. Stettinerstraße 25, D-7030 Böblingen
:Phone. (please let me sleep peacefully)
:Shortcut. [pit]
:Version. 0.2
:Date. 13.06.88
:Copyright. PD
:Language. Modula-II
:Translator. M2Amiga
:Imports. LoadIFF.mod [fbs]
:UpDate. none
:Contents. Umwandlung von IFF-Bildern in M2-Source-Code für ImageData.
:Remark. Updated Version of V0.1
---------------------------------------------------------------------------*)
MODULE IFFtoCode;
FROM SYSTEM IMPORT ADR, ADDRESS, SHIFT, BITSET, LONGSET, CAST;
FROM Exec IMPORT UByte;
FROM Intuition IMPORT ScreenPtr,WindowPtr,CloseScreen,DisplayBeep;
FROM Arguments IMPORT NumArgs,GetArg;
FROM Arts IMPORT TermProcedure,Assert;
FROM IFFLoad IMPORT ReadILBM,ReadILBMFlags,ReadILBMFlagSet,IFFInfo;
FROM Graphics IMPORT RastPortPtr,BitMapPtr;
FROM InOut IMPORT WriteString,WriteLn,WriteHex,WriteInt,OpenOutput,
CloseOutput;
FROM Strings IMPORT Length,Copy,Insert;
VAR MyScreen,
MyOldScreen :ScreenPtr;
MyWindow :WindowPtr;
Name,PtrName,
CurrentName,
CONSTName :ARRAY[0..79] OF CHAR;
length,i,
Eingabe,
Durchgang :INTEGER;
Error :BOOLEAN;
len :LONGINT;
BitMaps :ARRAY[0..5] OF ADDRESS;
ScLineLength,
LineLength,
Plane :LONGINT;
Pictheight,
Pictdepth,
Pictwidth :LONGINT;
AnzEingaben :INTEGER;
RP :RastPortPtr;
BM :BitMapPtr;
HeaderDone :BOOLEAN;
mehrDim :BOOLEAN;
AnzElem,Ae,
AnzZiff :LONGINT;
PROCEDURE CleanUp;
BEGIN
IF MyScreen<>NIL THEN CloseScreen(MyScreen) END;
END CleanUp;
PROCEDURE PointerName(Name:ARRAY OF CHAR;VAR PName:ARRAY OF CHAR);
VAR l :INTEGER;
BEGIN
l:=Length(Name);
Copy(PName,Name,0,79);
Insert(PName,l,"Ptr");
END PointerName;
PROCEDURE WritePlaneDat(BitMaps:ARRAY OF ADDRESS;Pictwidth,Pictheight,
Pictdepth,ScLineLength:LONGINT;
Name,PtrName,CName:ARRAY OF CHAR);
VAR Location :POINTER TO UByte;
Plane :CARDINAL;
Line,
ByteStep,Bstep,
Bs :LONGINT;
Index :CARDINAL;
ItemsPerLine :LONGINT;
PROCEDURE WriteHeader(VAR Done:BOOLEAN); (* Schreibt die Deklarationen *)
BEGIN
WriteLn;
WriteString(" (* -------> DEFINITION MODULE <-------- *)");
WriteLn;
WriteLn;
WriteString("DEFINITION MODULE "); WriteString(Name); WriteString(";");
WriteLn; WriteLn;
WriteString("FROM SYSTEM IMPORT WORD;");
WriteLn; WriteLn;
WriteString("FROM Heap IMPORT AllocMem;");
WriteLn; WriteLn;
WriteString("TYPE Img=RECORD"); WriteLn;
WriteString(" Dat:ARRAY [0.."); WriteInt(AnzElem,AnzZiff);
WriteString("] OF WORD;"); WriteLn;
WriteString(" END;"); WriteLn;
WriteLn; WriteLn;
IF mehrDim THEN
WriteString("CONST ");
FOR i:=1 TO AnzEingaben DO
GetArg(i,CONSTName,length);
WriteString(CONSTName); WriteString("=");WriteInt(i-1,3);WriteString(";");
WriteLn; WriteString(" ");
END;
WriteLn; WriteLn;
END;
WriteString("VAR "); WriteString(Name); WriteString("width :INTEGER;");
WriteLn;
WriteString(" "); WriteString(Name); WriteString("height :INTEGER;");
WriteLn;
WriteString(" "); WriteString(Name); WriteString("depth :INTEGER;");
WriteLn;
WriteString(" "); WriteString(PtrName);
IF mehrDim THEN
WriteString(" :ARRAY [0.."); WriteInt(AnzEingaben-1,3);
WriteString("] OF POINTER TO Img;"); WriteLn;
WriteLn; WriteLn;
ELSE
WriteString(" :POINTER TO Img;");
WriteLn; WriteLn;
END;
WriteString("END "); WriteString(Name); WriteString(".");
WriteLn; WriteLn;
WriteString(" (* -------> IMPLEMENTATION MODULE <-------- *)");
WriteLn;
WriteLn;
WriteString("IMPLEMENTATION MODULE "); WriteString(Name); WriteString(";");
WriteLn; WriteLn;
WriteString("FROM SYSTEM IMPORT WORD;");
WriteLn; WriteLn;
WriteString("FROM Heap IMPORT AllocMem;");
WriteLn; WriteLn;
IF mehrDim THEN
WriteString("VAR i :INTEGER;");
WriteLn; WriteLn;
END;
WriteLn; WriteLn;
WriteString("BEGIN (* MAIN *)");
WriteLn; WriteLn;
IF mehrDim THEN
WriteString("FOR i:=0 TO ");
WriteInt(AnzEingaben-1,3); WriteString(" DO"); WriteLn;
WriteString(" AllocMem("); WriteString(PtrName);
WriteString("[i],SIZE("); WriteString(PtrName);
WriteString("[i]^),TRUE);"); WriteLn;
WriteString("END;");
ELSE
WriteString("AllocMem("); WriteString(PtrName);
WriteString(",SIZE("); WriteString(PtrName);
WriteString("^),TRUE);"); WriteLn;
END;
WriteLn; WriteLn;
WriteString(Name); WriteString("width"); WriteString(" :=");
WriteInt(Pictwidth*8,3); WriteString(";");
WriteLn;
WriteString(Name); WriteString("height"); WriteString(":=");
WriteInt(Pictheight,3); WriteString(";");
WriteLn;
WriteString(Name); WriteString("depth"); WriteString(" :=");
WriteInt(Pictdepth,3); WriteString(";");
WriteLn; WriteLn;
Done:=TRUE;
END WriteHeader;
(* ********************* WritePlaneDat ********************* *)
BEGIN
AnzElem:=Pictwidth*Pictdepth*Pictheight DIV 2-1;
Ae:=AnzElem;
AnzZiff:=1;
WHILE Ae>10 DO;
Ae:=Ae DIV 10;
AnzZiff:=AnzZiff+1; (* Anzahl der Ziffern des größten Indexes *)
END;
IF AnzZiff<=3 THEN
ItemsPerLine:=4;
ELSE
ItemsPerLine:=3;
END;
IF NOT HeaderDone THEN
WriteHeader(HeaderDone);
END;
WriteLn; WriteLn;
WriteString("WITH "); WriteString(PtrName);
IF mehrDim THEN
WriteString("["); WriteString(CName); WriteString("]");
END;
WriteString("^ DO (* ");
WriteString(CName); WriteString(" *)");
WriteLn;
WriteLn;
Index:=0;
ItemsPerLine:=ItemsPerLine*2; (* 2 Bytes per Item *)
(*Pictwidth:=Pictwidth*2;*)
FOR Plane := 0 TO Pictdepth-1 DO
WriteString(" (* Plane "); WriteInt(Plane+1,1); WriteString(" *)");
WriteLn;
FOR Line := 0 TO Pictheight-1 DO
ByteStep:=0;
LOOP
Bstep:=ByteStep;
REPEAT
WriteString(" Dat[");
WriteInt(Index,AnzZiff);
Index:=Index+1;
WriteString("]:=0");
FOR Bs:=Bstep TO Bstep+1 DO
Location:=ADDRESS(BitMaps[Plane]+ ScLineLength*Line+Bs);
WriteHex(Location^,2); (* Hex-Wert schreiben *)
END; (*FOR Bs*)
WriteString("H;");
Bstep:=Bstep+2;
IF Bs>=Pictwidth THEN
WriteString("(*"); WriteInt(Line+1,2); WriteString("*)");
WriteLn;
EXIT; (*Ende der Zeile des Brushes erreicht*)
END;
UNTIL Bstep>=ByteStep+ItemsPerLine;
WriteLn;
ByteStep:=ByteStep+ItemsPerLine;
END; (*LOOP*)
END; (*FOR Line*)
WriteLn;
END; (*FOR Plane*)
END WritePlaneDat;
BEGIN (* MAIN *)
Name:="Img";
TermProcedure(CleanUp);
HeaderDone:=FALSE;
AnzEingaben:=NumArgs();
IF AnzEingaben>1 THEN mehrDim:=TRUE END;
WriteLn;
WriteString("IFFtoCode Version 0.2 by Pit Burkhardt");
WriteLn;WriteLn;
IF AnzEingaben=0 THEN
WriteString("Sorry, can't work - no Input!"); WriteLn;WriteLn;
WriteString("From CLI: Name IFF-file(s) as option."); WriteLn;WriteLn;
WriteString("From Workbench: <SHIFT>-klick IFF-file(s),"); WriteLn;
WriteString("then <SHIFT>-doubleklick IFFtoCode"); WriteLn; WriteLn;
ELSE
WriteString("Enter Name of Source-file to be generated or press <RETURN>");
WriteLn;
OpenOutput(" ");
PointerName(Name,PtrName);
FOR Eingabe:=1 TO AnzEingaben DO
Durchgang:=Eingabe-1;
GetArg(Eingabe,CurrentName,length);
MyOldScreen:=MyScreen;
IF MyOldScreen<>NIL THEN CloseScreen(MyOldScreen) END;
Error:=ReadILBM(CurrentName,ReadILBMFlagSet{visible},MyScreen,MyWindow);
Assert((Error),ADR("Fehler beim Laden des ILBM-Files"));
Pictdepth:=IFFInfo.BMHD.depth;
Pictheight:=IFFInfo.BMHD.height;
Pictwidth:=IFFInfo.BMHD.width;
LineLength := SHIFT(Pictwidth,-3); (*ergibt Zeilenlänge in Bytes*)
IF LineLength*8<Pictwidth THEN
WriteString("(* Brushbreite gegenüber IFF geändert! *)"); WriteLn;
LineLength:=LineLength+2;
END;
ScLineLength:= SHIFT(MyScreen^.width,-3);
RP := ADR(MyScreen^.rastPort);
BM := RP^.bitMap;
FOR i:=0 TO Pictdepth-1 DO
BitMaps[i] := BM^.planes[i];
END;
WritePlaneDat(BitMaps,LineLength,Pictheight,Pictdepth,ScLineLength,
Name,PtrName,CurrentName);
WriteString("END; ");
WriteLn;
END; (*FOR i*)
WriteString("END "); WriteString(Name); WriteString(".");
WriteLn;
CloseOutput;
WriteLn;
WriteString("Thanks! It was a pleasure to work with you ...");
WriteLn;
END; (*IF*)
END IFFtoCode.